package com.island.model;

import java.util.LinkedHashSet;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

import org.hibernate.annotations.Cascade;

@Entity
@Table(name="users")
public class User {

	private int userID;//用户主键ID
	private String userName;//用户名称
	private String password;//用户密码
	private String sex;//用户性别，0：男，1：女。
	private int age;//用户年龄
	private String phone;//用户电话号码
	private String createdate;//用户创建日期
	private int masterID;//创建者ID
	private String trueName;//用户真实姓名
	
	private Set<Role> roles=new LinkedHashSet<Role>();//角色集合
	
	@Id @GeneratedValue
    @Column(name="userid", unique=true, nullable=false)
	public int getUserID() {
		return userID;
	}
	public void setUserID(int userID) {
		this.userID = userID;
	}
	
	@Column(name="username")
	public String getUserName() {
		return userName;
	}
	public void setUserName(String userName) {
		this.userName = userName;
	}
	
	@Column(name="password")
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	
	@Column(name="sex")
	public String getSex() {
		return sex;
	}
	public void setSex(String sex) {
		this.sex = sex;
	}
	
	@Column(name="age")
	public int getAge() {
		return age;
	}
	public void setAge(int age) {
		this.age = age;
	}
	
	@Column(name="phone")
	public String getPhone() {
		return phone;
	}
	public void setPhone(String phone) {
		this.phone = phone;
	}
	
	@Column(name="createdate")
	public String getCreatedate() {
		return createdate;
	}
	public void setCreatedate(String createdate) {
		this.createdate = createdate;
	}
	
	@Column(name="masterid")
	public int getMasterID() {
		return masterID;
	}
	public void setMasterID(int masterID) {
		this.masterID = masterID;
	}
	
	@Column(name="trueName")
	public String getTrueName() {
		return trueName;
	}
	public void setTrueName(String trueName) {
		this.trueName = trueName;
	}
	
	@ManyToMany(fetch = FetchType.LAZY) 
	@Cascade(value={org.hibernate.annotations.CascadeType.SAVE_UPDATE})
	@JoinTable(name="userrole", joinColumns={@JoinColumn(name="userID")}, 
	 inverseJoinColumns={@JoinColumn(name="roleID")}) 
	public Set<Role> getRoles() {
		return roles;
	}
	public void setRoles(Set<Role> roles) {
		this.roles = roles;
	}
}
